package LiKouBrushQuestions;

import java.util.Collection;
import java.util.Iterator;
import java.util.Queue;
import java.util.Stack;

public class June_29 {
    public static void main(String[] args) {
        System.out.println("虽千万难，吾亦愿往！ ----29");
    }
}

/**
 * @author 23737
 * @time 6.29  0.40
 * 剑指offer 12
 * 矩阵中的路径
 */
class SolutionPathInArray {
    public boolean exist(char[][] board, String word) {
        //先检查是否可以进行寻找（检查是否满足条件）
        if (board.length == 0 || board[0].length == 0 || board == null || word == null) { // 判断是否为空, 为空则直接返回false
            return false;
        }
        //获取二维矩阵的行数和列数
        int row = board.length;
        int colomu = board[0].length;
        //表示已经找到的字符串的数目
        int IsFind = 0;
        //记录是否可以走
        int[][] hs = new int[row][colomu];

        for (int i = 0; i < row; i++) {
            for (int j = 0; j < colomu; j++) {
                if (board[i][j] == word.charAt(IsFind)) {
                    hs[i][j]++;
                    if (IsFind == word.length() - 1 || SearchFind(i, j, IsFind + 1, board, word, hs)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    private boolean SearchFind(int i, int j, int i1, char[][] board, String word, int[][] hs) {
        // 往上搜索
        if (i - 1 >= 0 && hs[i - 1][j] == 0 && board[i - 1][j] == word.charAt(i1)) {
            hs[i - 1][j] = hs[i][j] + 1;
            if (i1 == word.length() - 1 || SearchFind(i - 1, j, i1 + 1, board, word, hs)) {
                return true;
            }
        }
        // 往下搜索
        if (i + 1 < board.length && hs[i + 1][j] == 0 && board[i + 1][j] == word.charAt(i1)) {
            hs[i + 1][j] = hs[i][j] + 1; // 可以根据数组元素大小顺序模拟出路径
            if (i1 == word.length() - 1 || SearchFind(i + 1, j, i1 + 1, board, word, hs)) {
                return true;
            }
        }
        // 往左搜索
        if (j - 1 >= 0 && hs[i][j - 1] == 0 && board[i][j - 1] == word.charAt(i1)) {
            hs[i][j - 1] = hs[i][j] + 1;
            if (i1 == word.length() - 1 || SearchFind(i, j - 1, i1 + 1, board, word, hs)) {
                return true;
            }
        }

        // 往右搜索
        if (j + 1 < board[0].length && hs[i][j + 1] == 0 && board[i][j + 1] == word.charAt(i1)) {
            hs[i][j + 1] = hs[i][j] + 1;
            if (i1 == word.length() - 1 || SearchFind(i, j + 1, i1 + 1, board, word, hs)) {
                return true;
            }
        }
        hs[i][j] = 0;
        return false;
    }
}


/**
 * @time 6.29 15.44
 * 剑指 offer 06  从头到尾打印链表
 */
class ListNodeTwo {
    int val;
    ListNode next;
    ListNodeTwo(int x) {
        val = x;
    }
}
class SolutionLianBiao {
    public int[] reversePrint(ListNode head) {
        Stack<ListNode> integers = new Stack<>();
        ListNode temp = head;
        while (temp != null) {
            integers.push(temp);
            temp = temp.next;
        }
        int size = integers.size();
        int[] Reverse = new int[size];
//        int[] Reverse = new int[integers.size()];
        System.out.println("长度" + integers.size());
        for (int i = 0; i < size; i++) {
            Reverse[i] = integers.pop().val;
        }
        return Reverse;
    }
}






